package com.ruoyi.web.controller.com;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.enums.CommonBusiEnum;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.OperateBasicForm;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.com.domain.ComBusinessContent;
import com.ruoyi.com.service.IComBusinessContentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务管理-内容发布Controller
 *
 * @author sunye
 * @date 2024-12-07
 */
@RestController
@RequestMapping("/com/comBusinessContent")
@Api(tags = "业务管理-内容发布")
public class ComBusinessContentController extends BaseController
{
    @Autowired
    private IComBusinessContentService comBusinessContentService;

    /**
     * 查询业务管理-内容发布列表
     */
    @ApiOperation(value = "查询业务管理-内容发布列表")
    @GetMapping("/list")
    public TableDataInfo list(ComBusinessContent comBusinessContent)
    {
        startPage();
        comBusinessContent.setDeptId(getDeptId());
        comBusinessContent.setSmallId(getSmallId());
        List<ComBusinessContent> list = comBusinessContentService.selectComBusinessContentList(comBusinessContent);
        return getDataTable(list);
    }


    /**
     * 按照分类id查询内容发布列表
     */
    @ApiOperation(value = "按照分类id查询内容发布列表")
    @GetMapping("/getListByClassifyId")
    public TableDataInfo getListByClassifyId(ComBusinessContent comBusinessContent)
    {
        startPage();
        comBusinessContent.setDeptId(getDeptId());
        comBusinessContent.setSmallId(getSmallId());
        List<ComBusinessContent> list = comBusinessContentService.getListByClassifyId(comBusinessContent);
        return getDataTable(list);
    }

    /**
     * 获取业务管理-内容发布详细信息
     */
    @ApiOperation(value = "获取业务管理-内容发布详细信息")
    @GetMapping(value = "/{contentId}")
    public AjaxResult getInfo(@PathVariable("contentId") Long contentId)
    {
        return success(comBusinessContentService.selectComBusinessContentByContentId(contentId));
    }

    /**
     * 新增业务管理-内容发布
     */
    @ApiOperation(value = "新增业务管理-内容发布")
    @Log(title = "业务管理-内容发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComBusinessContent comBusinessContent)
    {
        comBusinessContent.setCreateId(getUserId());
        comBusinessContent.setDeptId(getDeptId());
        comBusinessContent.setSmallId(getSmallId());
        comBusinessContent.setTerminalType(CommonBusiEnum.APPLY_TERMINAL_XCX.getCode());//小程序
        //comBusinessContent.setTerminalType(CommonBusiEnum.APPLY_TERMINAL_DLDP.getCode());//导览大屏
        return toAjax(comBusinessContentService.insertComBusinessContent(comBusinessContent));
    }

    /**
     * 修改业务管理-内容发布
     */
    @ApiOperation(value = "修改业务管理-内容发布")
    @Log(title = "业务管理-内容发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComBusinessContent comBusinessContent)
    {
        comBusinessContent.setUpdateId(getUserId());
        return toAjax(comBusinessContentService.updateComBusinessContent(comBusinessContent));
    }

    /**
     * 删除业务管理-内容发布
     */
    @ApiOperation(value = "删除业务管理-内容发布")
    @Log(title = "业务管理-内容发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contentIds}")
    public AjaxResult remove(@PathVariable Long[] contentIds)
    {
        return toAjax(comBusinessContentService.deleteComBusinessContentByContentIds(contentIds));
    }


    /**
     * 置为有效/无效业务管理-内容发布
     */
    @Log(title = "置为无效业务管理-内容发布", businessType = BusinessType.UPDATE)
    @PostMapping("effectiveStatus")
    @ApiOperation(value = "置为有效/无效业务管理-内容发布")
    public AjaxResult effectiveStatus(@RequestBody OperateBasicForm operateBasicForm)
    {
        return toAjax(comBusinessContentService.effectiveStatus(operateBasicForm));
    }
}
